from tkinter import font
from B_Data import *
from D_Individual import *

import numpy as np
import B_Data
import E_SetAdp
from matplotlib import pyplot as plt, axes, font_manager
import matplotlib
from mpl_toolkits.mplot3d import Axes3D

Zh_Font = matplotlib.font_manager.FontProperties(fname="../venv/include/SourceHanSansSC-Bold.otf")
plt.rc('font', family='Times New Roman')
plt.rc('font', size=16)
plt.rc('font', weight='bold')
legend_font = {
    'fname': 'C:/Windows/fonts/simhei.ttf',  # 引用系统字体
    'style': 'normal',
    'size': 50,  # 字号
    'weight': "bold",  # 是否加粗，不加粗
}
# 画甘特图(构件工序甘特图)
def Draw_Gatt_New():
    # n*3行 【n构件】
    # 开始时间
    # 结束时间
    # 持续时间

    plt.figure(figsize=(35, 15))
    M = ['dimgray', 'tan', 'darkgreen', 'royalblue', 'lightcoral', 'gold', 'lightseagreen',
         'blue', 'red', 'darkslategrey', 'darkviolet', 'orangered', 'yellow', 'deepskyblue',
         'fuchsia', 'saddlebrown', 'lawngreen', 'dodgerblue', 'lightgreen', 'pink']
    pc_names = np.array(['', 'pc_0_01_0', 'pc_0_02_0', 'pc_0_03_0', 'pc_0_02_1'])
    pc_0_01_0 = [[0,1,2,3,4,5],[8,12,18,21,29,34],[1,1,1,1,1,1]]
    pc_0_02_0 = [[2,5,7,9,11,13],[17,19,26,35,37,43],[2,2,2,2,2,2,2]]
    pc_0_03_0 = [[7,8,11,12,13,15],[3,12,22,28,33,36],[1,1,1,1,1,1]]
    pc_0_02_1 = [[9,13,15,17,19,21],[10,14,29,31,36,39],[2,2,2,2,2,2,2]]
    # 遍历构件的每个工序
    for Process_Index in range(6):
        Start_time = pc_0_01_0[0][Process_Index]  # 开始时间
        End_time   = pc_0_01_0[1][Process_Index]  # 结束时间
        Last_Time  = pc_0_01_0[2][Process_Index]  # 持续时间
        plt.barh(1, width=Last_Time, left=Start_time, color=M[Process_Index], edgecolor='white')   # 工序（每个）甘特图：x轴数据，宽度，起始位置，颜色，边缘）
    # 遍历构件的每个工序
    for Process_Index in range(6):
        Start_time = pc_0_02_0[0][Process_Index]  # 开始时间
        End_time   = pc_0_02_0[1][Process_Index]  # 结束时间
        Last_Time  = pc_0_02_0[2][Process_Index]  # 持续时间
        plt.barh(2, width=Last_Time, left=Start_time, color=M[Process_Index], edgecolor='white')  # 工序（每个）甘特图：x轴数据，宽度，起始位置，颜色，边缘）
    # 遍历构件的每个工序
    for Process_Index in range(6):
        Start_time = pc_0_03_0[0][Process_Index]  # 开始时间
        End_time   = pc_0_03_0[1][Process_Index]  # 结束时间
        Last_Time  = pc_0_03_0[2][Process_Index]  # 持续时间
        plt.barh(3, width=Last_Time, left=Start_time, color=M[Process_Index],edgecolor='white')  # 工序（每个）甘特图：x轴数据，宽度，起始位置，颜色，边缘）
    # 遍历构件的每个工序
    for Process_Index in range(6):
        Start_time = pc_0_02_1[0][Process_Index]  # 开始时间
        End_time   = pc_0_02_1[1][Process_Index]  # 结束时间
        Last_Time  = pc_0_02_1[2][Process_Index]  # 持续时间
        plt.barh(4, width=Last_Time, left=Start_time, color=M[Process_Index], edgecolor='white')  # 工序（每个）甘特图：x轴数据，宽度，起始位置，颜色，边缘）
    plt.xticks(np.arange(0, 25, 1), fontsize=45, fontproperties=Zh_Font)  # np.arange(0,27,1)
    plt.yticks(np.arange(0, 5, 1), pc_names, fontsize=45, fontproperties=Zh_Font)  # B_Data.Production_Line
    plt.title("构件生产调度甘特图", fontsize=50, fontproperties=Zh_Font)
    plt.legend(B_Data.Production_class, frameon=False, prop=legend_font, bbox_to_anchor=(0.85, 0.1), loc=8, borderaxespad=0)
    plt.ylabel('构件编号', fontsize=50, fontproperties=Zh_Font)
    plt.xlabel('单位生产时间', fontsize=50, fontproperties=Zh_Font)
    plt.show()

if __name__ == "__main__":
    Draw_Gatt_New()